home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / program / cgrphxdv.lha / CGraphX / C / Examples / ScreenModeReq.c < prev    next >
C/C++ Source or Header  |  1995-11-29  |  5KB  |  223 lines

  1.  
  2. #include <exec/memory.h>
  3. #include <graphics/gfxbase.h>
  4. #include <intuition/intuitionbase.h>
  5. #include <libraries/asl.h>
  6. #include <cybergraphics/cybergraphics.h>
  7.  
  8. #ifdef __SASC_60
  9. #include <proto/asl.h>
  10. #include <proto/cybergraphics.h>
  11. #include <proto/dos.h>
  12. #include <proto/exec.h>
  13. #include <proto/graphics.h>
  14. #include <proto/intuition.h>
  15. #else
  16. #include <clib/asl_protos.h>
  17. #include <clib/cybergraphics_protos.h>
  18. #include <clib/dos_protos.h>
  19. #include <clib/exec_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/intuition_protos.h>
  22. #endif
  23.  
  24. #include <stdlib.h>
  25.  
  26. #define CYBERGFXNAME     "cybergraphics.library"
  27. #define CYBERGFXVERSION  40L
  28.  
  29. #ifdef __SASC_650
  30. /* use SAS/C 6.5x's autoinit feature */
  31.  
  32. LONG __oslibversion   = 39L;
  33. LONG __CGFXlibversion = CYBERGFXVERSION;
  34. #else
  35. struct GfxBase *GfxBase;
  36. struct IntuitionBase *IntuitionBase;
  37. struct Library *AslBase,*CyberGfxBase;
  38. #endif
  39.  
  40. #ifdef __SASC_650
  41. char Version[] = "$VER: ScreenModeReq 0.1 " __AMIGADATE__ ;
  42. #else
  43. char Version[] = "$VER: ScreenModeReq 0.1 (" __COMMODORE_DATE__  ")";
  44. #endif
  45.  
  46. char ResultFormat[] = "You selected screen mode \"%s\".";
  47.  
  48. /*
  49.  
  50.         display error message
  51.  
  52. */
  53.  
  54. void ErrorF(char *Format,...)
  55.  
  56. {
  57.  void *Data;
  58.  
  59.  Data=&Format+1L;
  60.  if (Cli())
  61.   {
  62.    (void)VPrintf(Format,Data);
  63.    (void)FPutC(Output(),'\n');
  64.    (void)Flush(Output());
  65.   }
  66.  else
  67.   {
  68.    struct EasyStruct EasyStruct;
  69.    ULONG IDCMPFlags;
  70.  
  71.    EasyStruct.es_StructSize=sizeof(struct EasyStruct);
  72.    EasyStruct.es_Flags=0L;
  73.    EasyStruct.es_Title="Error";
  74.    EasyStruct.es_TextFormat=Format;
  75.    EasyStruct.es_GadgetFormat="Ok";
  76.  
  77.    IDCMPFlags=0L;
  78.    (void)EasyRequestArgs(NULL,&EasyStruct,&IDCMPFlags,Data);
  79.   }
  80. }
  81.  
  82. /*
  83.  
  84.         our filter hook function
  85.  
  86. */
  87.  
  88. #ifdef __SASC_60
  89. LONG __asm __interrupt __saveds
  90.      SMFilterFunc(register __a0 struct Hook *Hook,
  91.                   register __a1 ULONG DisplayID,
  92.                   register __a2 struct ScreenModeRequester *SMReq)
  93.  
  94. {
  95. /* filter all native graphics modes */
  96.  if (!IsCyberModeID(DisplayID)) return FALSE;
  97.  
  98. /* filter all modes with pixelformat PIXFMT_LUT8 */
  99.  return (GetCyberIDAttr(CYBRIDATTR_PIXFMT,DisplayID)!=PIXFMT_LUT8);
  100. }
  101. #else
  102. LONG __geta4
  103.      SMFilterFunc(__a0 struct Hook *Hook,
  104.                   __a1 ULONG DisplayID,
  105.                   __a2 struct ScreenModeRequester *SMReq)
  106.  
  107. {
  108. /* filter all native graphics modes */
  109.  if (!IsCyberModeID(DisplayID)) return FALSE;
  110.  
  111. /* filter all modes with pixelformat PIXFMT_LUT8 */
  112.  return (GetCyberIDAttr(CYBRIDATTR_PIXFMT,DisplayID)!=PIXFMT_LUT8);
  113. }
  114. #endif
  115.  
  116. struct Hook SMFilterHook = {NULL,NULL,(void *)SMFilterFunc,NULL,NULL};
  117.  
  118. /*
  119.  
  120.         main program
  121.  
  122. */
  123.  
  124. int main(int argc, char **argv)
  125.  
  126. {
  127.  struct ScreenModeRequester *SMReq;
  128.  
  129. #ifndef __SASC_650
  130.  if ((GfxBase=(struct GfxBase *)
  131.               OpenLibrary("graphics.library",39L))==NULL) return 10;
  132.  
  133.  if ((IntuitionBase=(struct IntuitionBase *)
  134.                     OpenLibrary("intuition.library",39L))==NULL)
  135.   {
  136.    CloseLibrary (&GfxBase->LibNode);
  137.  
  138.    return 10;
  139.   }
  140.  
  141.  if ((AslBase=OpenLibrary(AslName,39L))==NULL)
  142.   {
  143.    CloseLibrary (&IntuitionBase->LibNode);
  144.    CloseLibrary (&GfxBase->LibNode);
  145.  
  146.    return 20;
  147.   }
  148.  
  149.  if ((CyberGfxBase=OpenLibrary(CYBERGFXNAME,CYBERGFXVERSION))==NULL)
  150.   {
  151.    CloseLibrary (AslBase);
  152.    CloseLibrary (&IntuitionBase->LibNode);
  153.    CloseLibrary (&GfxBase->LibNode);
  154.  
  155.    ErrorF ("Can't open \"%s\" version %ld or newer.",
  156.            CYBERGFXNAME,CYBERGFXVERSION);
  157.    return 10;
  158.   }
  159. #endif
  160.  
  161.  if ((SMReq=AllocAslRequestTags(ASL_ScreenModeRequest,
  162.                                 ASLSM_TitleText,"CyberGraphX",
  163.                                 ASLSM_FilterFunc,&SMFilterHook,
  164.                                 TAG_DONE))==NULL)
  165.   {
  166. #ifndef __SASC_650
  167.    CloseLibrary (CyberGfxBase);
  168.    CloseLibrary (AslBase);
  169.    CloseLibrary (&IntuitionBase->LibNode);
  170.    CloseLibrary (&GfxBase->LibNode);
  171. #endif
  172.  
  173.    ErrorF ("Can't create screen mode requester\n");
  174.    return 10;
  175.   }
  176.  
  177.  if (AslRequestTags(SMReq,TAG_DONE))
  178.   {
  179.    struct NameInfo NameInfo;
  180.  
  181.    if (GetDisplayInfoData(NULL,
  182.                           (UBYTE *)&NameInfo,
  183.                           sizeof(struct NameInfo),
  184.                           DTAG_NAME,
  185.                           SMReq->sm_DisplayID))
  186.     {
  187.      char *Ptr;
  188.  
  189.      Ptr=NameInfo.Name;
  190.      if (Cli())
  191.       {
  192.        (void)VPrintf(ResultFormat,&Ptr);
  193.        (void)FPutC(Output(),'\n');
  194.        (void)Flush(Output());
  195.       }
  196.      else
  197.       {
  198.        struct EasyStruct EasyStruct;
  199.        ULONG IDCMPFlags;
  200.  
  201.        EasyStruct.es_StructSize=sizeof(struct EasyStruct);
  202.        EasyStruct.es_Flags=0L;
  203.        EasyStruct.es_Title="Result";
  204.        EasyStruct.es_TextFormat=ResultFormat;
  205.        EasyStruct.es_GadgetFormat="Ok";
  206.  
  207.        IDCMPFlags=0L;
  208.        (void)EasyRequestArgs(NULL,&EasyStruct,&IDCMPFlags,&Ptr);
  209.       }
  210.     }
  211.   }
  212.  
  213.  FreeAslRequest (SMReq);
  214. #ifndef __SASC_650
  215.  CloseLibrary (CyberGfxBase);
  216.  CloseLibrary (AslBase);
  217.  CloseLibrary (&IntuitionBase->LibNode);
  218.  CloseLibrary (&GfxBase->LibNode);
  219. #endif
  220.  
  221.  return 0;
  222. }
  223.